import { Select, SelectProps } from "antd"
import { useEffect, useState } from "react"


interface ProSelectProps extends SelectProps {
    request?: any
    showLable?: string,
}

const ProSelect = ({ request, fieldNames, showLable, ...props }: ProSelectProps) => {
    const [options, setOptions] = useState([]);
    useEffect(() => {
        if (request) {
            console.log({ request })
            request().then(res => {
                setOptions([...res.records.map(v => {
                    return {
                        title: `${v[fieldNames.label]}-${showLable ? v[showLable] : v[fieldNames.value]}`,
                        label: v[fieldNames.label],
                        value: v[fieldNames.value],
                        item:v,
                    }
                })])
                // console.log('res', res)
            });
        }

    }, [request])
    return <Select {...props} options={options} optionLabelProp='title' />
}
export default ProSelect